﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MADDate
{
    class Date
    {

        private int day, month, year; 

        public int getDay() { return day; }
        public int getMonth() { return month; }
        public int getYear() { return year; }

        private Boolean isValidDay(int d, int m, int y)
        {
            return (d > 0) && (d == maxDay(m, y)); 
        }

        private Boolean isValidMonth(int m)
        {
            return m > 0 && m <= 12; 
        }

        private Boolean has31Days(int m)
        {
            return (m < 8 && m % 2 != 0) || (m >= 8 && m % 2 == 0);
        }

        private Boolean isValidYear(int y)
        {
            return y >= 0 ; 
        }

        private Boolean isLeapYear(int y)
        {
            return (y >= 1582) && (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));        
        }

        private Boolean isFebruary(int m)
        {
            return !has31Days(m) && m == 2; 
        }

        public Date(int d, int m, int y)
        {
            set(d, m, y); 
        }

        override public String ToString()
        {
            return day.ToString()+"."+month.ToString() + "." + year.ToString(); 
        }

        // Queries 
        public Boolean isValidDate(int d, int m, int y)
        {
            return isValidDay(d, m, y) && isValidMonth(m) && isValidYear(y); 
        }

        public int maxDay(int m, int y)
        {
            int res = 31;
            if (isFebruary(m) && !isLeapYear(y)) res = 28;
            else if (isFebruary(m) && isLeapYear(y)) res = 29;
            else if(!has31Days(m)) res = 30;
            return res; 
        }


        // Actions 
        public void set(int d, int m, int y)
        {
            day = isValidDay(d,m,y) ? d : 22;
            month = isValidMonth(m) ? m : 3;
            year = isValidYear(y) ? y : 2013; 
        }

        public void pass()
        {
        }

    }
}
